/**
 * Time:2022/1/4 10:07
 * Author:
 * Description:
 */

#ifndef HELLO_CPP_KMMAP_H
#define HELLO_CPP_KMMAP_H

#include <stdio.h>
#include <android/log.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <string>

#define WRITE_SUCCESS 0
#define WRITE_ERROR -1
#define WRITE_FULL 1
using namespace std;

class KMmap {
public:
    KMmap(const char *_filePointer, int _mmapBlockSize);

    /**
     * 当基类的派生类中有重写过基类的virtual方法的时候，
     * 使用基类的指针指向派生类的对象，
     * 调用这个方法实际上调用的会是派生类最后实现的方法
     */
    virtual ~KMmap();

public:
    bool initWrite();

    int write(const char *_dataPointer, int _writeLength);

private:
    int mmapBlockSize;
    int wroteSize = 0;
    const char *filePointer;
    int fileFd;
    char *mmapPointer;
};

#endif //HELLO_CPP_KMMAP_H
